package com.greenline.search.test.utils;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: liulei
 * Date: 13-12-31
 * Time: 上午11:01
 * To change this template use File | Settings | File Templates.
 */
public class ArrayUtils {

    public static String getTheMaxSumObject(List<String> stringList) {
        Map<String,Integer> countMap = new HashMap<String, Integer>();
        for(String str : stringList){
            if(countMap.containsKey(str)){
                countMap.put(str, countMap.get(str)+1);
            }else {
                countMap.put(str,1);
            }
        }

        String maxCountString = "";
        Integer maxCount = 0;
        for(String key : countMap.keySet()){
            if(countMap.get(key) > maxCount){
                maxCount = countMap.get(key);
                maxCountString = key;
            }
        }
        return maxCountString;
    }

    public static void main(String[] args) throws IOException {
        String url = "http://10.10.100.153:9999/doctor_search?q=%E5%86%A0%E5%BF%83%E7%97%85&fl=department_uuid&sort=doctor_haoyuan_level%20desc,score%20desc,pop%20desc";
        List<String> deptList = JSONStreamParserForAnalyze.parseDoctorSearchResponse(url);

        System.out.println("The max sum object is: "+getTheMaxSumObject(deptList));
    }
}
